package satellite

import (
	"sync"
	"sync/atomic"
)

var (
	trafficPool = sync.Pool{}
)

func init() {
	trafficPool.New = func() interface{} {
		traffic := &Traffic{}
		return traffic
	}
}

type Traffic struct {
	read  int64
	write int64
}

func NewTraffic() *Traffic {
	traffic := trafficPool.Get().(*Traffic)
	traffic.write = 0
	traffic.read = 0
	return traffic
}

func (traffic *Traffic) Read(i int64) {
	atomic.AddInt64(&traffic.read, i)
}

func (traffic *Traffic) Write(i int64) {
	atomic.AddInt64(&traffic.write, i)
}

func (traffic *Traffic) Close() {
	trafficPool.Put(traffic)
}
